#define FUSE_USE_VERSION 26

#include <fuse.h>
#include <fuse/fuse_lowlevel.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sqlite3.h>

#include <iostream>
#include <iterator>

using namespace std;

#include "FileSystem.h"
#include "Database.h"
#include "Tag.h"
#include "fuse.h"
#include "DirInit.h"
#include "DirWalker.h"

FileSystem *fs = NULL;
																														     
static struct fuse_operations tagfs_oper;

using namespace std;

int main(int argc, char *argv[]) {

	tagfs_oper.getattr = tagfs_getattr;
	tagfs_oper.readdir = tagfs_readdir;
	tagfs_oper.mkdir = tagfs_mkdir;
	tagfs_oper.rmdir = tagfs_rmdir;
	tagfs_oper.mknod = tagfs_mknod;
	tagfs_oper.write = tagfs_write;
	tagfs_oper.read = tagfs_read;
	tagfs_oper.setxattr = tagfs_setxattr;
	tagfs_oper.flush = tagfs_flush;
	tagfs_oper.unlink = tagfs_unlink;
	tagfs_oper.utimens = tagfs_utimens;
	tagfs_oper.chmod = tagfs_chmod;
	tagfs_oper.chown = tagfs_chown;
	tagfs_oper.ftruncate = tagfs_ftruncate;
	tagfs_oper.readlink = tagfs_readlink;
	tagfs_oper.symlink = tagfs_symlink;
	
	DirInit init;
	init.initDirs(argc, argv);
	
	char *mount = init.getMountDir();
	char *repo = init.getRepoDir();
	char *args[2] = { (char*)"tagfs", mount };
//	char *args[3] = { "tagfs", mount, "-d" };
	
	fs = new FileSystem(repo);
	
	if (init.shouldBuild()){
		DirWalker walker(fs);
		string dir = init.getBuildDir();
		walker.walk_dir(dir);
	};
    
    return fuse_main(2, args, &tagfs_oper, 0);

}
																			     
